package com.zry.fertilizer.view

import android.app.Activity
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.widget.LinearLayout
import com.zry.fertilizer.R
import com.zry.fertilizer.animation.RecyclerViewUtilKt
import com.zry.fertilizer.been.CustomerInfo

class CustomerInfoPopup(activity: Activity?, linearLayout: LinearLayout, customerInfoList: MutableList<CustomerInfo>) : BasePopup(activity!!, R.layout.document_status_popup, linearLayout) {


    init {
        val documentStatusRecycler: RecyclerView = contentView!!.findViewById(R.id.documentStatusRecycler)
        val recyclerViewUtilKt = RecyclerViewUtilKt(activity!!, documentStatusRecycler)
        recyclerViewUtilKt.initRecyclerView()
        val customerInfoAdapter = CustomerInfoAdapter(R.layout.item_document_status_popup, customerInfoList)
        recyclerViewUtilKt.setAdapter(customerInfoAdapter)
        customerInfoAdapter.setOnItemClickListener { adapter, view, position ->
            if (listener != null) {
                listener?.handleResult(customerInfoList[position])
            }
            popupWindow?.dismiss()
        }
    }


    private var listener: CustomerInfoListener? = null

    interface CustomerInfoListener {
        fun handleResult(customerInfo: CustomerInfo)
    }

    fun setListener(listener: CustomerInfoListener): CustomerInfoPopup {
        this.listener = listener
        return this
    }
}
